package com.lotterymanage.page;

import java.util.List;

/**
 * 分页信息类 作为各个分页查询的基类.
 * @author ponder
 */
public class Pagination {
    /**
     * 总页数.
     */
    private int totalPage;
    private int currentPage;
    private int totalRow;
    private int startRow;
    private int endRow;
    private int previousPage;
    private int nextPage;
    private boolean hasPreviousPage;
    private boolean hasNextPage;
    private String column = "";
    private String order = "";

    /**
     * 列表数据.
     */
    private List<Object> dataList;

    /**
     * 默认每页显示的记录条数.
     */
    public static final int DEFAULT_ONE_PAGE_ROW = 10;

    /**
     * Constructor for the Pagination object.
     * @param newTotalCount 总记录数
     * @param newCurrentPage 当前页码
     */
    public Pagination(final int newTotalCount, final int newCurrentPage) {
        this(newTotalCount, newCurrentPage, DEFAULT_ONE_PAGE_ROW, null, null);
    }

    /**
     * Constructor for the Pagination object.
     * @param newTotalCount 总记录数
     * @param newCurrentPage 当前页码
     * @param newShowNum 显示条数
     */
    public Pagination(final int newTotalCount, final int newCurrentPage,
            final int newShowNum) {
        this(newTotalCount, newCurrentPage, newShowNum, null, null);
    }

    /**
     * Constructor for the Pagination object.
     * @param newTotalCount 总记录数
     * @param newCurrentPage 当前页码
     * @param newShowNum 显示条数
     * @param _column 要排序的字段
     * @param _order 排序 asc or desc
     */
    public Pagination(final int newTotalCount, final int newCurrentPage,
            final int newShowNum, final String _column, final String _order) {
        int howNum = newShowNum <= 0 ? DEFAULT_ONE_PAGE_ROW : newShowNum;

        totalPage = ((newTotalCount - 1) / howNum) + 1;
        currentPage = newCurrentPage;
        currentPage = (currentPage <= 0) ? 1 : currentPage;
        currentPage = (currentPage > totalPage) ? totalPage : currentPage;
        totalRow = newTotalCount;
        startRow = ((currentPage - 1) * howNum) + 1;
        endRow = (startRow + howNum) - 1;
        endRow = (endRow > newTotalCount) ? newTotalCount : endRow;
        previousPage = currentPage - 1;
        nextPage = currentPage + 1;
        if (currentPage > 1) {
            hasPreviousPage = true;
        }
        if (currentPage < totalPage) {
            hasNextPage = true;
        }
        this.column = _column;
        this.order = _order;

    }

    /**
     * 取得当前页码.
     * @return int 当前页码
     */
    public int getCurrentPage() {
        return currentPage;
    }

    /**
     * 取得结束行号.
     * @return int 结束行号
     */
    public int getEndRow() {
        return endRow;
    }

    /**
     * 是否有下一页.
     * @return boolean 是否有下一页
     */
    public boolean isHasNextPage() {
        return hasNextPage;
    }

    /**
     * 是否有上一页.
     * @return boolean 是否有上一页
     */
    public boolean isHasPreviousPage() {
        return hasPreviousPage;
    }

    /**
     * 取得下一页.
     * @return int 下一页
     */
    public int getNextPage() {
        return nextPage;
    }

    /**
     * 取得下一页.
     * @return int 上一页
     */
    public int getPreviousPage() {
        return previousPage;
    }

    /**
     * 取得开始行号.
     * @return int 开始行号
     */
    public int getStartRow() {
        return startRow;
    }

    /**
     * 取得总页数.
     * @return int 总页数
     */
    public int getTotalPage() {
        return totalPage;
    }

    /**
     * 取得总记录数.
     * @return int 总记录数
     */
    public int getTotalRow() {
        return totalRow;
    }

    /**
     * 设置当前页码.
     * @param i 当前页码
     */
    public void setCurrentPage(final int i) {
        currentPage = i;
    }

    /**
     * 设置结束的记录号.
     * @param i 结束的记录号
     */
    public void setEndRow(final int i) {
        endRow = i;
    }

    /**
     * 设置是否有下一页.
     * @param b 是否有下一页
     */
    public void setHasNextPage(final boolean b) {
        hasNextPage = b;
    }

    /**
     * 设置是否有上一页.
     * @param b 是否有上一页
     */
    public void setHasPreviousPage(final boolean b) {
        hasPreviousPage = b;
    }

    /**
     * 设置下一页.
     * @param i 下一页
     */
    public void setNextPage(final int i) {
        nextPage = i;
    }

    /**
     * 设置上一页.
     * @param i 上一页
     */
    public void setPreviousPage(final int i) {
        previousPage = i;
    }

    /**
     * 设置开始行号.
     * @param i 开始行号
     */
    public void setStartRow(final int i) {
        startRow = i;
    }

    /**
     * 设置总页数.
     * @param i 总页数
     */
    public void setTotalPage(final int i) {
        totalPage = i;
    }

    /**
     * 设置总记录数.
     * @param i 总记录数
     */
    public void setTotalRow(final int i) {
        totalRow = i;
    }

    /**
     * 返回列.
     * @return Returns the column.
     */
    public String getColumn() {
        return column;
    }

    /**
     * @param _column The column to set.
     */
    public void setColumn(final String _column) {
        this.column = _column;
    }

    /**
     * @return Returns the order.
     */
    public String getOrder() {
        return order;
    }

    /**
     * @param _order The order to set.
     */
    public void setOrder(final String _order) {
        this.order = _order;
    }

    /**
     * 取得mysql的开始行数.
     * @return int 开始行数
     */
    public int getMysqlStartRow() {
        return this.getStartRow() - 1;
    }

    /**
     * 取得mysql的条数.
     * @return int 条数
     */
    public int getMysqlRowCnt() {
        return this.getEndRow() - this.getStartRow() + 1;
    }

    /**
     * @return the dataList
     */
    public List<Object> getDataList() {
        return dataList;
    }

    /**
     * @param _dataList the dataList to set
     */
    public void setDataList(final List<Object> _dataList) {
        dataList = _dataList;
    }

}
